$(".dao li").hover(
  function () {
    $("#show-nav").css("backgroundColor", "#fff");
    $(this).children("#second").slideDown(); //缓动
  },
  function () {
    $("#show-nav").css("backgroundColor", "transparent");
    $(this).children("#second").css("display", "none");
  }
);
//   修改商品数量
$("#all").on("click", ".add", function () {
  var id = $(this).parents("tr").children().eq(0).text();
  $.ajax({
    url: "http://localhost/ht-shop/src/php/update.php",
    data: {
      id: id,
      type: "add",
    },
    success: function (res) {
      if (res.code === 1) {
        show();
      }
    },
    dataType: "json",
  });
});

$("#all").on("click", ".cut", function () {
  var id = $(this).parents("tr").children().eq(0).text();
  console.log(id);
  $.ajax({
    url: "http://localhost/ht-shop/src/php/update.php",
    data: {
      id: id,
      type: "cut",
    },
    success: function (res) {
      if (res.code === 1) {
        show();
      }
    },
    dataType: "json",
  });
});
// 删除购物车数据
$("#all").on("click", ".del", function () {
  var id = $(this).parents("tr").children().eq(0).text();
  $.ajax({
    url: "http://localhost/ht-shop/src/php/del.php",
    data: {
      id: id,
    },
    success: function (res) {
      if (res.code === 1) {
        show();
      }
    },
    dataType: "json",
  });
});
// 展示购物车数据
show();
function show() {
  $.ajax({
    url: "http://localhost/ht-shop/src/php/showlist.php",
    success: function (res) {
      $("#all").html(`<tr>
                    <th>编号</th>
                    <th>商品名</th>
                    <th>图片</th>
                    <th>价格</th>
                    <th>数量</th>
                    <th>删除</th>
                </tr>   `);
      if (res.code == 1) {
        res.data.forEach(function (val) {
          $("#all").append(`<tr>
            <td>${val.product_id}</td>
            <td style="width:200px;text-align:center">${val.product_name}</td>
            <td>
                <img src="${val.product_img}" alt="">
            </td>
            <td style="width:100px;text-align:center">
                ${val.product_price}
            </td>
            <td style="width:300px;text-align:center">
                <span class="cut">-</span>
                <input type="text" value='${val.product_num}' disabled>
                <span class="add">+</span>
            </td>
            <td style="width:60px;text-align:center">
                <input type="button" value="删除" class="del">
            </td>
        </tr>`);
        });
      }
    },
    dataType: "json",
  });
}
// 总价
var aa = $("#all").find(".s3").text();
console.log(aa);
